/*******************************************************************************
File: 7_cpfp_self_involvement
Project: CPKIN
Purpose: This .do file cleans and analyzes CPFP data on involvement of CPFPs in child protection activities 
Author: Akshay Dixit
Date Created: Feb 20, 2019
Date modified: July 2, 2020
********************************************************************************/

clear all
set more off

***THIS IS THE INPUT THAT MUST BE CHANGED SPECIFIC TO THE USER***
*gl identity ""
*gl user "" 

********************************************************************************

***Creating Global File Paths***'
gl data "$user/data"
gl dof "$user/do files"
gl analysis "$user/analysis"

********************************************************************************

u "$data/endline_fp_data.dta", clear
tab treatment	//65 treatment, 57 control, 122 total

preserve
	contract village_id1 treatment chiefdom
	isid village_id1
	tab treatment					//59 (out of 64) treatment villages, 56 (out of 62) control villages
	tab chiefdom
restore

* Stratification variable - Chiefdom
gl chiefdom = "bagruwa_chief barri_chief bumpeh_chief fakunya_chief gallinas_perri_chief kaiyamba_chief kamarjei_chief kori_chief kowa_chief kpaka_chief malin_chief sowa_chief"

* Control variables
gl controls = "wealth_index female age attend_school fp_visit vil_pop"

count if focal_status == .	//No missing values
forvalues i=1/3 {
	g focal_status_`i' = (focal_status == `i')
}	

		/*
		An additional control needed is focal person status: currently active, replaced, previous FP.			
		*/

********************************************************************************
		
* Outcome variables

desc fp_pnsh_hvywork fp_sev_beat fp_care fp_med fp_study fp_needs fp_preg fp_sch

foreach var in fp_pnsh_hvywork fp_sev_beat fp_care {
	di "`var'"
	
	//Replacing outcome = "Never" if response = "This incident has not happened in the village in the past 6 months"
	replace `var' = 0 if `var' == .d
	
	//Converting into a binary variable to prevent undue outlier influence, and make comparable with other datasets
	replace `var' = 1 if (`var' == 2 | `var' == 3)
	
	tab `var'
	tab treatment, sum(`var')
}

foreach var in fp_med fp_study fp_needs fp_preg fp_sch {
	di "`var'"
	
	//Replacing outcome = "Never" if response = "This incident has not happened in the village in the past 6 months"
	replace `var' = 0 if `var' == .d
	
	//Converting into a binary variable to prevent undue outlier influence, and make comparable with other datasets
	replace `var' = 1 if (`var' == 2 | `var' == 3)
	
	tab `var'
	tab treatment, sum(`var')
}

* Label variables

lab var fp_pnsh_hvywork "FP involvement (binary): Punishing adult for forcing child to do heavy work"
lab var fp_sev_beat "FP involvement (binary): Punishing adult for severely beating child"
lab var fp_care "FP involvement (binary): Care and protection for child severely beaten"
lab var fp_med "FP involvement in helping children get medical care/medicine"
lab var fp_study "FP involvement in providing encouragement to study"
lab var fp_needs "FP involvement in providing assistance to children for their basic needs"
lab var fp_preg "FP involvement in helping pregnant minors get medical care"
lab var fp_sch "FP involvement in helping out of school children return to school"

lab var treatment "Treatment"
lab var wealth_index "Wealth index" 
lab var female "Female"
lab var age "Age"
lab var attend_school "Ever attended school" 
lab var fp_visit "Village visited by UNICEF monitoring team"
lab var vil_pop "Village population"
lab var chief "Respondent: Chief"
lab var sms_received "CPKIN SMS received"
lab var focal_status_1 "FP status: Current active, never replaced"
lab var focal_status_2 "FP status: Current active, replaced prior FP in past year"
lab var focal_status_3 "FP status: Previous FP, replaced in past year" 

********************************************************************************

*** Export ITT estimates to Excel for making bar graphs ***

cd "$analysis"
	
putexcel set "cpfp_plots.xlsx", sheet(cpfp_involvement_1) modify

putexcel A1=("Group") B1=("Punishing adult for forcing child to do heavy work") C1=("Punishing adult for severely beating child") D1=("Care and protection for child severely beaten")
putexcel E1=("1.96se1") F1=("1.96se2") G1=("1.96se3") 
putexcel A2=("Control") A3=("Treatment") 

reg fp_pnsh_hvywork treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum fp_pnsh_hvywork if treatment == 0
putexcel B2 = (r(mean))
putexcel B3 = ((_b[treatment]) + (r(mean)))
putexcel E3 = (1.96*(_se[treatment]))

reg fp_sev_beat treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum fp_sev_beat if treatment == 0
putexcel C2 = (r(mean))
putexcel C3 = ((_b[treatment]) + (r(mean)))
putexcel F3 = (1.96*(_se[treatment]))

reg fp_care treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum fp_care if treatment == 0
putexcel D2 = (r(mean))
putexcel D3 = ((_b[treatment]) + (r(mean)))
putexcel G3 = (1.96*(_se[treatment]))


putexcel set "cpfp_plots.xlsx", sheet(cpfp_involvement_2) modify

putexcel A1=("Group") B1=("Helping children get medical care") 
putexcel C1=("Providing encouragement to study") D1=("Providing assistance for basic needs") 
putexcel E1=("Helping pregnant minors get medical care") F1=("Helping out of school children return to school") 
putexcel G1=("1.96se1") H1=("1.96se2") I1=("1.96se3") J1=("1.96se4") K1=("1.96se5") 
putexcel A2=("Control") A3=("Treatment") 

reg fp_med treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum fp_med if treatment == 0
putexcel B2 = (r(mean))
putexcel B3 = ((_b[treatment]) + (r(mean)))
putexcel G3 = (1.96*(_se[treatment]))

reg fp_study treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum fp_study if treatment == 0
putexcel C2 = (r(mean))
putexcel C3 = ((_b[treatment]) + (r(mean)))
putexcel H3 = (1.96*(_se[treatment]))

reg fp_needs treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum fp_needs if treatment == 0
putexcel D2 = (r(mean))
putexcel D3 = ((_b[treatment]) + (r(mean)))
putexcel I3 = (1.96*(_se[treatment]))

reg fp_preg treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum fp_preg if treatment == 0
putexcel E2 = (r(mean))
putexcel E3 = ((_b[treatment]) + (r(mean)))
putexcel J3 = (1.96*(_se[treatment]))

reg fp_sch treatment $chiefdom $controls focal_status_2 focal_status_3, vce(robust) 
sum fp_sch if treatment == 0
putexcel F2 = (r(mean))
putexcel F3 = ((_b[treatment]) + (r(mean)))
putexcel K3 = (1.96*(_se[treatment]))

******************************************************************************** 
 
clear

